// 判断是否有特殊情况
const data = require('./data.json')
const fs = require('fs')
const { log } = require('console')

// 分析薪资待遇
function countWage() {
  let str = '11-12K·13薪'
  let reg = /(\d+)/g

  let result_obj = {
    '-5': [],
    '5-10': [],
    '10-15': [],
    '15-20': [],
    '20-': [],
  }
  data.forEach((item) => {
    // 去除实习薪资
    if (item['wage'].indexOf('元') >= 0) {
      return
    }
    //去除公司虚假额度薪资
    let wage = parseInt(item['wage'].match(reg)[1]) - 1

    if (wage < 5) {
      result_obj['-5'].push(item)
    } else if (5 <= wage && wage < 10) {
      result_obj['5-10'].push(item)
    } else if (10 <= wage && wage < 15) {
      result_obj['10-15'].push(item)
    } else if (15 <= wage && wage < 20) {
      result_obj['15-20'].push(item)
    } else {
      result_obj['20-'].push(item)
    }
  })

  // console.log(result_obj)

  let keys = Object.keys(result_obj)
  keys.forEach((item) => {
    console.log(result_obj[item].length)
  })
}

// 统计福利待遇
function countWellBing() {
  let data_list = data.map((value, index) => {
    return value.well_bing.split('，')
  })
  //   console.log(data_list)
  fs.writeFileSync('wordCloud_well_bing.json', JSON.stringify(data_list.flat()))
}

// 统计技能数据
function countSkill() {
  let skill_list = data.map((item, index) => {
    return item.skill_tags
  })
  fs.writeFileSync('wordCloud_skills.json', JSON.stringify(skill_list.flat()))
}

// 统计行业分类
function countType() {
  let industry_list = data.map((item, index) => {
    return item.industry
  })
  fs.writeFileSync('anaylysis_inductry.json', JSON.stringify(industry_list))
}

// 求总数据
function getListDesc() {
  function avgFunc(array) {
    //将array的长度赋给len
    let len = array.length
    let sum = 0
    //利用for循环遍历数组的内容，利用sum累加求和
    for (let i = 0; i < len; i++) {
      sum += array[i]
    }
    //        返回数组的和与长度求平均值
    return sum / len
  }

  let reg = /(\d+)/g
  let wage_list = []
  // 中位数统计
  let middle = 0
  // 平均值统计
  let avg = 0
  data.forEach((item) => {
    // 去除实习薪资
    if (item['wage'].indexOf('元') >= 0) {
      return
    }
    let min = parseInt(item['wage'].match(reg)[0])
    let max = parseInt(item['wage'].match(reg)[1])
    wage_list.push((min + max) / 2)
  })
  wage_list.sort((a, b) => a - b)
  middle = wage_list[143]
  avg = avgFunc(wage_list)

  console.log('岗位总数量：', wage_list.length)
  console.log('工资中位数：', middle)
  console.log('工资平均值：', avg)
}

// 获取所有地址
function analysisMapCpunt() {
  //   获取单位所在区域
  // 按照点分配，获得最后一个值
  let list = data.map((item, index) => {
    let temp = item.address.replace(/·/g, '')
    item.address = temp
    return item.address
  })
  console.log(list)
  // 计算权重
  // 获得数值
  fs.writeFileSync('address.json', JSON.stringify(list))
}

// 地址去重
function uniqueAddress() {
  const addressData = require('./address.json')
  let uniSet = new Set(addressData)
  console.log(uniSet)
}

// request请求获取坐标地址
/**
 * 数据格式
 * {
 * "长春南关区净月开发区":{"lng":125.37610053134287,"lat":43.86820140370632}
 * }
 */
function reset(params) {}
